# -*- coding: utf-8 -*-
"""
@Project ：weather 
@File    ：log_config.py
@Author: guzain
@Date:  2025/7/7 11:30:03
@Email： GZA5210@163.com
@Description: 日志配置
"""
import logging
import os
import datetime

# 确保logs目录存在
LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs')
os.makedirs(LOG_DIR, exist_ok=True)

# 日志文件名，按日期命名
LOG_FILE = os.path.join(LOG_DIR, f'diy_weather_{datetime.datetime.now().strftime("%Y-%m-%d")}.log')

# 配置logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler(LOG_FILE, encoding='utf-8'),  # 输出到文件
        logging.StreamHandler()  # 同时输出到控制台
    ]
)

# 创建logger实例
logger = logging.getLogger(__name__)
